<?php

@date_default_timezone_set("Asia/Taipei");

/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

$targetFolder = "";
$targetFolder = '/bloodPet/uploads/news';

if (!empty($_FILES)) {
	
	$datetime = date("YmdHis");
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
	$fileParts = pathinfo($_FILES['Filedata']['name']);
	$targetFile = rtrim($targetPath,'/') . '/'.$datetime.$fileParts["basename"];
	
	// Validate the file type
	$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
	$fileParts = pathinfo($_FILES['Filedata']['name']);
	
	if (!file_exists($targetPath)) {
	    mkdir($targetPath, 0, true);
	}
	
	if (in_array($fileParts['extension'],$fileTypes)) {
		move_uploaded_file($tempFile,$targetFile);
		echo $targetFolder . '/' .$datetime.$_FILES['Filedata']['name'];
	} else {
		echo 'Invalid file type.';
	}
}
?>